package org.jeecg.modules.wms.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.wms.entity.WmsInventory;
import org.jeecg.modules.wms.vo.WmsInventoryVO;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 库存管理
 */
public interface IWmsInventoryService extends IService<WmsInventory> {

    /**
     * 分页查询库存列表
     */
    IPage<WmsInventoryVO> queryInventoryPageList(Page<WmsInventoryVO> page, Map<String, Object> params);
    
    /**
     * 查询物料在特定仓库的库存
     */
    List<WmsInventoryVO> queryByMaterialAndWarehouse(String materialId, String warehouseId);
    
    /**
     * 入库
     */
    boolean inbound(WmsInventory inventory, BigDecimal quantity, Integer businessType, String businessNo, String operator, String remark);
    
    /**
     * 出库
     */
    boolean outbound(WmsInventory inventory, BigDecimal quantity, Integer businessType, String businessNo, String operator, String remark);
    
    /**
     * 库存调整
     */
    boolean adjust(WmsInventory inventory, BigDecimal quantity, Integer businessType, String businessNo, String operator, String remark);
    
    /**
     * 库存移动
     */
    boolean move(WmsInventory inventory, String targetWarehouseId, String targetLocationId, BigDecimal quantity, 
                Integer outboundBusinessType, Integer inboundBusinessType, String businessNo, String operator, String remark);
    
    /**
     * 带成本的出库
     */
    boolean outboundWithCost(WmsInventory inventory, BigDecimal quantity, Integer businessType, String businessNo, String operator, String remark);
    
    /**
     * 库存成本调整
     */
    boolean adjustCost(WmsInventory inventory, BigDecimal newUnitCost, Integer businessType, String businessNo, String operator, String remark);
    
    /**
     * 带成本的入库，使用参数映射
     * @param params 入库参数映射，包含物料信息、仓库库位、数量、成本等
     * @return 是否成功
     */
    boolean inboundWithCostAndParams(Map<String, Object> params);
    
    /**
     * 根据物料编号、物料类型和出库数量查询可用库存信息
     * @param materialCode 物料编号
     * @param materialType 物料类型
     * @param requiredQuantity 需求数量
     * @return 可用库存列表
     */
    List<WmsInventoryVO> queryAvailableInventoryForOutbound(String materialCode, String materialType, BigDecimal requiredQuantity);
    
    /**
     * 移动端库存查询
     * @param page 分页参数
     * @param params 查询参数，包含searchKeyword、materialTypes、stockStatuses等
     * @return 分页查询结果
     */
    IPage<WmsInventoryVO> queryInventoryForMobile(Page<WmsInventoryVO> page, Map<String, Object> params);
    
    /**
     * 导出库存列表
     * @param params 查询参数
     * @param response HTTP响应对象
     */
    void exportInventoryList(Map<String, Object> params, HttpServletResponse response);
}